//index.js
//获取应用实例
const encrypt = require("../../utils/encrypt.js")
const app = getApp()

Page({
  data: {
    currentPage:1,
    userInfo: {},
    hasUserInfo: false,
    canIUse: wx.canIUse('button.open-type.getUserInfo'),
    banner: [{ src: 'http://www.ever-clean.com.cn/images/default_slidershow/1.jpg' }, { src: 'http://www.ever-clean.com.cn/images/default_slidershow/2.jpg' }, { src: 'http://www.ever-clean.com.cn/images/default_slidershow/3.jpg' }, { src: 'http://www.ever-clean.com.cn/images/default_slidershow/4.jpg' }, { src: 'http://www.ever-clean.com.cn/images/default_slidershow/5.jpg' }],
    indicatorDots: true,
    vertical: false,
    autoplay: true,
    interval: 2000,
    duration: 500,
    color:'#ccc',
    activecolor:"#fff",
    news: [],
    message: []
  },

  onLoad: function () {

    var that =this;
    var parameter = encrypt.encode(JSON.stringify({ currentPage: this.data.currentPage }));
    var data = { parameter: parameter}
    app.request(encrypt.url + 'getCNewsList.ashx', data, function (res){
      
      if (res.data.code == 200) {
        let newlist = res.data.data.newsList;
        
        var newsList = []
        for(let i = 0;i<3;i++){
          
          newsList.push({ time: newlist[i].NewsDate.split('/')[0] + '-' + newlist[i].NewsDate.split('/')[1], title: newlist[i].NewsTitle, id: newlist[i].ID})
        }
        
        that.setData({
          news: newsList
        })
        
      }
    })

    app.request(encrypt.url + 'getHNewsList.ashx', data, function (res) {

      if (res.data.code == 200) {
        let newlist = res.data.data.newsList;
        
        var newsList = []
        for (let i = 0; i < 3; i++) {

          newsList.push({ time: newlist[i].NewsDate.split('/')[0] + '-' + newlist[i].NewsDate.split('/')[1], title: newlist[i].NewsTitle, id: newlist[i].ID })
        }
        
        that.setData({
          message: newsList
        })

      }
    })
  },
  homeJump:function(){
    wx.switchTab({
      url: '../index/index'
    })
  },
  aboutJump:function(){
    wx.navigateTo({
      url: '../aboutUs/aboutUs'
    })
  },
  aboutJump2: function () {
    wx.navigateTo({
      url: '../aboutUs/aboutUs'
    })
  },
  serveJump:function(){
    app.globalData.classifyId = 0
    wx.switchTab({
      url: '../serve/serve',
      success: function () {

        var page = getCurrentPages().pop();
        if (page == undefined || page == null) return;
        page.onLoad();
      }
    })
  },
  serveJump2: function () {
    app.globalData.classifyId = 0
    wx.switchTab({
      url: '../serve/serve',
      success: function () {

        var page = getCurrentPages().pop();
        if (page == undefined || page == null) return;
        page.onLoad();
      }
    })
  },
  serverChange1:function(){
    app.globalData.classifyId = 0
    wx.switchTab({
      url: '../serve/serve',
      success: function () {

        var page = getCurrentPages().pop();
        if (page == undefined || page == null) return;
        page.onLoad();
      }
    })
  },
  serverChange2: function () {
    app.globalData.classifyId = 1
    wx.switchTab({
      url: '../serve/serve',
      success:function(){
        
        var page = getCurrentPages().pop();
        if (page == undefined || page == null) return;
        page.onLoad();
      }
    })
  },
  serverChange3: function () {
    app.globalData.classifyId = 2
    wx.switchTab({
      url: '../serve/serve',
      success: function () {
        var page = getCurrentPages().pop();
        if (page == undefined || page == null) return;
        page.onLoad();
      }
    })
  },
  serverChange4: function () {
    app.globalData.classifyId = 3
    wx.switchTab({
      url: '../serve/serve',
      success: function () {
        var page = getCurrentPages().pop();
        if (page == undefined || page == null) return;
        page.onLoad();
      }
    })
  },
  default2:function() {
    app.globalData.classifyId = 0
    wx.switchTab({
      url: '../serve/serve',
      success: function () {

        var page = getCurrentPages().pop();
        if (page == undefined || page == null) return;
        page.onLoad();
      }
    })
  },
  scienceJump:function(){
    wx.navigateTo({
      url: '../science/science'
    })
  },
  newsJump:function(){
    app.globalData.newsindex = 0
    wx.switchTab({
      url: '../news/news',
      success: function () {

        var page = getCurrentPages().pop();
        if (page == undefined || page == null) return;
        page.onLoad();
      }
    })
  },
  newsJump1: function () {
    app.globalData.newsindex = 1
    wx.switchTab({
      url: '../news/news',
      success: function () {

        var page = getCurrentPages().pop();
        if (page == undefined || page == null) return;
        page.onLoad();
      }
    })
  },
  newsJump2: function () {
    app.globalData.newsindex = 2
    wx.switchTab({
      url: '../news/news',
      success: function () {

        var page = getCurrentPages().pop();
        if (page == undefined || page == null) return;
        page.onLoad();
      }
    })
  },
  cultureJump:function(){
    wx.navigateTo({
      url: '../culture/culture'
    })
  },
  recruitJump:function(){
    wx.navigateTo({
      url: '../recruit/recruit'
    })
  },
  contactJump:function(){
    wx.switchTab({
      url: '../contact/contact'
    })
  },
  newsJumps: function (e) { //新闻跳转
    var id = e.currentTarget.dataset.id

    wx.navigateTo({
      url: '../newsDetail/newsDetail?id=' + id,
    })
  },
  messageJump: function (e) {//时讯跳转
    var id = e.currentTarget.dataset.id
    wx.navigateTo({
      url: '../eventDetail/eventDetail?id=' + id,
    })
  },
})
